package org.sport.dbImplement;

import org.sport.dbInterface.HisInfoOperation;
import org.sport.model.entityModel.GrouptableEntity;
import org.sport.model.entityModel.HistoryinfotableEntity;
import org.sport.model.entityModel.UsertableEntity;
import org.sport.repository.HistoryinfotableRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Allen on 2017/9/22.
 */
@Service
public class HisInfoOpeImp implements HisInfoOperation{

    @Autowired
    HistoryinfotableRepository hisInfoRepository;

    @Override
    public boolean addOneCheatInfo(HistoryinfotableEntity historyinfotableEntity) {
        if(historyinfotableEntity != null)
        {
            hisInfoRepository.saveAndFlush(historyinfotableEntity);
            return true;
        }
        else
            return false;
    }

    @Override
    public boolean delOneCheatInfo(HistoryinfotableEntity historyinfotableEntity) {
        if(historyinfotableEntity != null)
        {
            hisInfoRepository.delete(historyinfotableEntity);
            return true;
        }
        else
            return false;
    }

    @Override
    public HistoryinfotableEntity findOne(HistoryinfotableEntity historyinfotableEntity) {
        return null;
    }

    @Override
    public List<HistoryinfotableEntity> findAllHisInfo() {
        return hisInfoRepository.findAll();
    }

    @Override
    public List<HistoryinfotableEntity> findAllHisInfoByWho2Who(UsertableEntity who, UsertableEntity toWho) {
        return hisInfoRepository.findByWhoToWho(who,toWho);
    }

    /**
     * 返回一个人的所有聊天信息
     *
     * @param who
     * @return
     */
    @Override
    public List<HistoryinfotableEntity> findAllHisInfoByWho(UsertableEntity who) {
        return hisInfoRepository.findByUserId(who);
    }

    @Override
    public List<HistoryinfotableEntity> findAllHisInfoByGroupId(GrouptableEntity grouptableEntity) {
        return hisInfoRepository.findByGroupId(grouptableEntity);
    }
}
